package com.open4cn.simulator.core.device;

import com.open4cn.simulator.core.connector.ConnectAddress;

import java.io.Serializable;
import java.util.StringJoiner;

/**
 * @author yinxiaopeng
 * @version 1.0.0
 * @company 致景科技
 * @department 飞梭BU/研发
 * @description
 * @Email yinxiaopeng@zj.tech
 * @date 2022-04-04 11:17
 */
public class DeviceInfo<P, S> implements Serializable {

    private String id;

    private String name;

    // 设备品牌
    private String brand;

    // 设备型号
    private String model;

    // 连接参数
    private ConnectAddress connectAddress;

    // 设备状态
    private DeviceStatus<S> deviceStatus;

    // 设备自定义参数
    private P parameters;

    public String getId() {
        if (null == id) {
            StringJoiner joiner = new StringJoiner("-");
            joiner.add(brand);
            joiner.add(model);
            joiner.add(connectAddress.getHost());
            joiner.add(String.valueOf(connectAddress.getPort()));
            joiner.add(connectAddress.getComPort());
            joiner.add(String.valueOf(connectAddress.getBaudRate()));
            setId(joiner.toString());
        }
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        if (null == name) {
            StringJoiner joiner = new StringJoiner("-");
            joiner.add(brand);
            joiner.add(model);
            setName(joiner.toString());
        }
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public DeviceStatus<S> getDeviceStatus() {
        return deviceStatus;
    }

    public void setDeviceStatus(DeviceStatus<S> deviceStatus) {
        this.deviceStatus = deviceStatus;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public ConnectAddress getConnectAddress() {
        return connectAddress;
    }

    public void setConnectAddress(ConnectAddress connectAddress) {
        this.connectAddress = connectAddress;
    }

    public P getParameters() {
        return parameters;
    }

    public void setParameters(P parameters) {
        this.parameters = parameters;
    }
}
